home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Programming / ace_gpl_release / src_ansi / ace / c / print.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-05  |  7.2 KB  |  286 lines

  1. /* << ACE >>
  2.  
  3.    -- Amiga BASIC Compiler --
  4.  
  5.    ** Parser: standard output and screen printing code **
  6.    ** Copyright (C) 1998 David Benn
  7.    ** 
  8.    ** This program is free software; you can redistribute it and/or
  9.    ** modify it under the terms of the GNU General Public License
  10.    ** as published by the Free Software Foundation; either version 2
  11.    ** of the License, or (at your option) any later version.
  12.    **
  13.    ** This program is distributed in the hope that it will be useful,
  14.    ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.    ** GNU General Public License for more details.
  17.    **
  18.    ** You should have received a copy of the GNU General Public License
  19.    ** along with this program; if not, write to the Free Software
  20.    ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  21.  
  22.    Author: David J Benn
  23.    Date: 26th October-30th November, 1st-13th December 1991,
  24.    14th,20th-27th January 1992, 
  25.    2nd-17th, 21st-29th February 1992, 
  26.    1st,13th,14th,22nd,23rd March 1992,
  27.    21st,22nd April 1992,
  28.    2nd,3rd,11th,15th,16th May 1992,
  29.    7th,8th,9th,11th,13th,14th,28th,29th,30th June 1992,
  30.    2nd-8th,14th-19th,26th-29th July 1992,
  31.    1st-3rd,7th,8th,9th August 1992,
  32.    6th,7th,13th December 1992,
  33.    6th January 1993,
  34.    18th February 1993,
  35.    10th,11th,31st October 1993,
  36.    14th,15th December 1993,
  37.    2nd January 1994
  38.  */
  39.  
  40. #include "acedef.h"
  41.  
  42. #define QUN_CODE 3
  43.  
  44. /* externals */
  45. extern int sym;
  46. extern int lastsym;
  47. extern int obj;
  48. extern BOOL end_of_source;
  49. extern BOOL dosused;
  50. extern int fstrcount;
  51.  
  52. /* functions */
  53. void gen_printcode (int code)
  54. {
  55.   switch (code)
  56.     {
  57.       /* LF */
  58.     case LF_CODE:
  59.       gen ("move.l", "#0", "-(sp)");
  60.       break;
  61.       /* TAB */
  62.     case TAB_CODE:
  63.       gen ("move.l", "#1", "-(sp)");
  64.       break;
  65.       /* SPACE */
  66.     case SPACE_CODE:
  67.       gen ("move.l", "#2", "-(sp)");
  68.       break;
  69.       /* QUN */
  70.     case QUN_CODE:
  71.       gen ("move.l", "#3", "-(sp)");
  72.       break;
  73.     }
  74.  
  75.   /* call function */
  76.   gen ("jsr", "_Ucodeprint", "  ");
  77.   gen ("addq", "#4", "sp");
  78.   enter_XREF ("_Ucodeprint");
  79. }
  80.  
  81. void print_statement (void)
  82. {
  83. /* - Print expression(s) to a DOS or Intuition window.
  84.    - Expressions can be separated by spaces, commas or semicolons.
  85.    - Text is clipped at the right edge of an Intuition window, but
  86.    wraps around in a DOS window. The former is in line with AmigaBASIC.
  87.    - Both window-types scroll text when the bottom is reached.
  88.  */
  89.   int exprtype, arguments = 0;
  90.  
  91.   enter_XREF ("_GfxBase");
  92.  
  93.   do
  94.     {
  95.       if (sym != ident && !strfunc () && !numfunc () && !factorfunc () &&
  96.       obj != constant)
  97.     insymbol ();        /* ident/func/literal after space or as first parameter */
  98.  
  99.       /* PRINT# ? */
  100.       if (sym == hash && (lastsym == printsym || lastsym == question))
  101.     return;
  102.  
  103.       /* end of line, multi-statement, ";", "," ELSE or comment 
  104.          after PRINT command word? -> don't proceed to expr! */
  105.       if ((sym == endofline) || (sym == colon) || (sym == apostrophe) ||
  106.       (sym == semicolon) || (sym == comma) || (sym == elsesym) ||
  107.       (end_of_source))
  108.     {
  109.       if (sym == comma)
  110.         gen_printcode (TAB_CODE);
  111.       else if ((arguments == 0) && (sym != semicolon))
  112.         gen_printcode (LF_CODE);    /* PRINT with no args */
  113.  
  114.       if (sym != colon && sym != elsesym)
  115.         insymbol ();    /* leave colon for multi-statement 
  116.                    in statement() or leave ELSE for if_statement() */
  117.       return;
  118.     }
  119.  
  120.       /* get an expression */
  121.       exprtype = expr ();
  122.  
  123.       if (exprtype == undefined)
  124.     {
  125.       _error (0);
  126.       return;
  127.     }            /* illegal syms? */
  128.  
  129.       switch (exprtype)
  130.     {
  131.     case shorttype:
  132.       make_long ();
  133.       gen ("jsr", "_Ushortprint", "  ");
  134.       gen ("addq", "#4", "sp");
  135.       enter_XREF ("_Ushortprint");
  136.       break;
  137.  
  138.     case longtype:
  139.       gen ("jsr", "_Ulongprint", "  ");
  140.       gen ("addq", "#4", "sp");
  141.       enter_XREF ("_Ulongprint");
  142.       break;
  143.  
  144.     case singletype:
  145.       gen ("jsr", "_Usingleprint", "  ");
  146.       gen ("addq", "#4", "sp");
  147.       enter_XREF ("_Usingleprint");
  148.       break;
  149.  
  150.     case stringtype:
  151.       gen ("jsr", "_Ustringprint", "  ");
  152.       gen ("addq", "#4", "sp");
  153.       enter_XREF ("_Ustringprint");
  154.       break;
  155.     }
  156.  
  157.       if (exprtype != stringtype)
  158.     gen_printcode (SPACE_CODE);    /* trailing space
  159.                        for any number */
  160.       arguments++;
  161.  
  162.       if (sym == comma)
  163.     gen_printcode (TAB_CODE);
  164.  
  165.     }
  166.   while ((sym == comma) || (sym == semicolon) || (sym == ident) ||
  167.      strfunc () || numfunc () || factorfunc () || obj == constant);
  168.  
  169.   /* no comma or semicolon at end of PRINT -> LF */
  170.   gen_printcode (LF_CODE);
  171.  
  172.   /* need mathffp.library for _Usingleprint and 
  173.      _beep if called by _Ustringprint. 
  174.    */
  175.   enter_XREF ("_MathBase");
  176. }
  177.  
  178. void gen_printscode (int code)
  179. {
  180.   switch (code)
  181.     {
  182.       /* LF */
  183.     case LF_CODE:
  184.       gen ("jsr", "_printsLF", "  ");
  185.       enter_XREF ("_printsLF");
  186.       break;
  187.       /* TAB */
  188.     case TAB_CODE:
  189.       gen ("jsr", "_printsTAB", "  ");
  190.       enter_XREF ("_printsTAB");
  191.       break;
  192.       /* SPACE */
  193.     case SPACE_CODE:
  194.       gen ("jsr", "_printsSPC", "  ");
  195.       enter_XREF ("_printsSPC");
  196.       break;
  197.     }
  198. }
  199.  
  200. void prints_statement (void)
  201. {
  202. /* - print expression(s) to current rastport (intended for screens or
  203.    Intuition windows).
  204.    - expressions can be separated by spaces, commas or semicolons which
  205.    have the same effect as in the PRINT statement.
  206.  */
  207.   int exprtype, arguments = 0;
  208.  
  209.   enter_XREF ("_GfxBase");
  210.  
  211.   do
  212.     {
  213.       if (sym != ident && !strfunc () && !numfunc () && !factorfunc () &&
  214.       obj != constant)
  215.     insymbol ();        /* ident/func/literal after space or as first parameter */
  216.  
  217.       /* end of line, multi-statement, ";", "," ELSE or comment 
  218.          after PRINTS command word? -> don't proceed to expr! */
  219.       if ((sym == endofline) || (sym == colon) || (sym == apostrophe) ||
  220.       (sym == semicolon) || (sym == comma) || (sym == elsesym) ||
  221.       (end_of_source))
  222.     {
  223.       if (sym == comma)
  224.         gen_printscode (TAB_CODE);
  225.       else if ((arguments == 0) && (sym != semicolon))
  226.         gen_printscode (LF_CODE);    /* PRINTS with no args */
  227.  
  228.       if (sym != colon && sym != elsesym)
  229.         insymbol ();    /* leave colon for multi-statement 
  230.                    in statement() or leave ELSE for if_statement() */
  231.       return;
  232.     }
  233.  
  234.       /* get an expression */
  235.       exprtype = expr ();
  236.  
  237.       if (exprtype == undefined)
  238.     {
  239.       _error (0);
  240.       return;
  241.     }            /* illegal syms? */
  242.  
  243.       switch (exprtype)
  244.     {
  245.     case shorttype:
  246.       gen ("move.w", "(sp)+", "d0");
  247.       gen ("jsr", "_shortprints", "  ");
  248.       enter_XREF ("_shortprints");
  249.       break;
  250.  
  251.     case longtype:
  252.       gen ("move.l", "(sp)+", "d0");
  253.       gen ("jsr", "_longprints", "  ");
  254.       enter_XREF ("_longprints");
  255.       break;
  256.  
  257.     case singletype:
  258.       gen ("move.l", "(sp)+", "d0");
  259.       gen ("jsr", "_singleprints", "  ");
  260.       enter_XREF ("_singleprints");
  261.       enter_XREF ("_MathBase");
  262.       break;
  263.  
  264.     case stringtype:
  265.       gen ("movea.l", "(sp)+", "a0");
  266.       gen ("jsr", "_stringprints", "  ");
  267.       enter_XREF ("_stringprints");
  268.       break;
  269.     }
  270.  
  271.       if (exprtype != stringtype)
  272.     gen_printscode (SPACE_CODE);    /* trailing space
  273.                        for any number */
  274.       arguments++;
  275.  
  276.       if (sym == comma)
  277.     gen_printscode (TAB_CODE);
  278.  
  279.     }
  280.   while ((sym == comma) || (sym == semicolon) || (sym == ident) ||
  281.      strfunc () || numfunc () || factorfunc () || obj == constant);
  282.  
  283.   /* no comma or semicolon at end of PRINTS -> LF */
  284.   gen_printscode (LF_CODE);
  285. }
  286.